
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 2016/3/21 1:39:12
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace yncTech.BusinessObjects
{
	/// <summary>
	/// Encapsulates the 'T_S_FunctionHelp' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(TSFunctionHelp))]	
	[XmlType("TSFunctionHelp")]
	public partial class TSFunctionHelp : esTSFunctionHelp
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new TSFunctionHelp();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Decimal functionID)
		{
			var obj = new TSFunctionHelp();
			obj.FunctionID = functionID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Decimal functionID, esSqlAccessType sqlAccessType)
		{
			var obj = new TSFunctionHelp();
			obj.FunctionID = functionID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("TSFunctionHelpCollection")]
	public partial class TSFunctionHelpCollection : esTSFunctionHelpCollection, IEnumerable<TSFunctionHelp>
	{
		public TSFunctionHelp FindByPrimaryKey(System.Decimal functionID)
		{
			return this.SingleOrDefault(e => e.FunctionID == functionID);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(TSFunctionHelp))]
		public class TSFunctionHelpCollectionWCFPacket : esCollectionWCFPacket<TSFunctionHelpCollection>
		{
			public static implicit operator TSFunctionHelpCollection(TSFunctionHelpCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator TSFunctionHelpCollectionWCFPacket(TSFunctionHelpCollection collection)
			{
				return new TSFunctionHelpCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class TSFunctionHelpQuery : esTSFunctionHelpQuery
	{
		public TSFunctionHelpQuery():this("TSFunctionHelpQuery")
		{
		}
		public TSFunctionHelpQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "TSFunctionHelpQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(TSFunctionHelpQuery query)
		{
			return TSFunctionHelpQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator TSFunctionHelpQuery(string query)
		{
			return (TSFunctionHelpQuery)TSFunctionHelpQuery.SerializeHelper.FromXml(query, typeof(TSFunctionHelpQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esTSFunctionHelp : esEntity
	{
		public esTSFunctionHelp()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Decimal functionID)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(functionID);
			else
				return LoadByPrimaryKeyStoredProcedure(functionID);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Decimal functionID)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(functionID);
			else
				return LoadByPrimaryKeyStoredProcedure(functionID);
		}

		private bool LoadByPrimaryKeyDynamic(System.Decimal functionID)
		{
			TSFunctionHelpQuery query = new TSFunctionHelpQuery();
			query.Where(query.FunctionID == functionID);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Decimal functionID)
		{
			esParameters parms = new esParameters();
			parms.Add("FunctionID", functionID);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to T_S_FunctionHelp.FunctionID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? FunctionID
		{
			get
			{
				return base.GetSystemDecimal(TSFunctionHelpMetadata.ColumnNames.FunctionID);
			}
			
			set
			{
				if(base.SetSystemDecimal(TSFunctionHelpMetadata.ColumnNames.FunctionID, value))
				{
					OnPropertyChanged(TSFunctionHelpMetadata.PropertyNames.FunctionID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_FunctionHelp.FunctionDesc
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FunctionDesc
		{
			get
			{
				return base.GetSystemString(TSFunctionHelpMetadata.ColumnNames.FunctionDesc);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionHelpMetadata.ColumnNames.FunctionDesc, value))
				{
					OnPropertyChanged(TSFunctionHelpMetadata.PropertyNames.FunctionDesc);
				}
			}
		}		
		
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "FunctionID": this.str().FunctionID = (string)value; break;							
						case "FunctionDesc": this.str().FunctionDesc = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "FunctionID":
						
							if (value == null || value is System.Decimal)
								this.FunctionID = (System.Decimal?)value;
								OnPropertyChanged(TSFunctionHelpMetadata.PropertyNames.FunctionID);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esTSFunctionHelp entity)
			{
				this.entity = entity;
			}
			
	
			public System.String FunctionID
			{
				get
				{
					System.Decimal? data = entity.FunctionID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionID = null;
					else entity.FunctionID = Convert.ToDecimal(value);
				}
			}
				
			public System.String FunctionDesc
			{
				get
				{
					System.String data = entity.FunctionDesc;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionDesc = null;
					else entity.FunctionDesc = Convert.ToString(value);
				}
			}
			

			private esTSFunctionHelp entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionHelpMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public TSFunctionHelpQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new TSFunctionHelpQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(TSFunctionHelpQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(TSFunctionHelpQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private TSFunctionHelpQuery query;		
	}



	[Serializable]
	abstract public partial class esTSFunctionHelpCollection : esEntityCollection<TSFunctionHelp>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionHelpMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "TSFunctionHelpCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public TSFunctionHelpQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new TSFunctionHelpQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(TSFunctionHelpQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new TSFunctionHelpQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(TSFunctionHelpQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((TSFunctionHelpQuery)query);
		}

		#endregion
		
		private TSFunctionHelpQuery query;
	}



	[Serializable]
	abstract public partial class esTSFunctionHelpQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionHelpMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "FunctionID": return this.FunctionID;
				case "FunctionDesc": return this.FunctionDesc;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem FunctionID
		{
			get { return new esQueryItem(this, TSFunctionHelpMetadata.ColumnNames.FunctionID, esSystemType.Decimal); }
		} 
		
		public esQueryItem FunctionDesc
		{
			get { return new esQueryItem(this, TSFunctionHelpMetadata.ColumnNames.FunctionDesc, esSystemType.String); }
		} 
		
		#endregion
		
	}


	
	public partial class TSFunctionHelp : esTSFunctionHelp
	{

		#region UpToTSFunctions - One To One
		/// <summary>
		/// One to One
		/// Foreign Key Name - T_S_FunctionHelp_FunctionID_FK1
		/// </summary>

		[XmlIgnore]
		public TSFunctions UpToTSFunctions
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
			
				if(this._UpToTSFunctions == null && FunctionID != null)
				{
					this._UpToTSFunctions = new TSFunctions();
					this._UpToTSFunctions.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToTSFunctions", this._UpToTSFunctions);
					this._UpToTSFunctions.Query.Where(this._UpToTSFunctions.Query.FunctionID == this.FunctionID);
					this._UpToTSFunctions.Query.Load();
				}

				return this._UpToTSFunctions;
			}
			
			set 
			{ 
				this.RemovePreSave("UpToTSFunctions");

				if(value == null)
				{
					this._UpToTSFunctions = null;
				}
				else
				{
					this._UpToTSFunctions = value;
					this.SetPreSave("UpToTSFunctions", this._UpToTSFunctions);
				}
				
				
			} 
		}
				
		
		private TSFunctions _UpToTSFunctions;
		#endregion

		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
			if(!this.es.IsDeleted && this._UpToTSFunctions != null)
			{
				this.FunctionID = this._UpToTSFunctions.FunctionID;
			}
		}
		
	}
	



	[Serializable]
	public partial class TSFunctionHelpMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected TSFunctionHelpMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(TSFunctionHelpMetadata.ColumnNames.FunctionID, 0, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = TSFunctionHelpMetadata.PropertyNames.FunctionID;
			c.IsInPrimaryKey = true;
			c.NumericPrecision = 18;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionHelpMetadata.ColumnNames.FunctionDesc, 1, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionHelpMetadata.PropertyNames.FunctionDesc;
			c.CharacterMaxLength = 2147483647;
			c.IsNullable = true;
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public TSFunctionHelpMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string FunctionID = "FunctionID";
			 public const string FunctionDesc = "FunctionDesc";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string FunctionID = "FunctionID";
			 public const string FunctionDesc = "FunctionDesc";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(TSFunctionHelpMetadata))
			{
				if(TSFunctionHelpMetadata.mapDelegates == null)
				{
					TSFunctionHelpMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (TSFunctionHelpMetadata.meta == null)
				{
					TSFunctionHelpMetadata.meta = new TSFunctionHelpMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("FunctionID", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("FunctionDesc", new esTypeMap("text", "System.String"));			
				
				
				
				meta.Source = "T_S_FunctionHelp";
				meta.Destination = "T_S_FunctionHelp";
				
				meta.spInsert = "proc_T_S_FunctionHelpInsert";				
				meta.spUpdate = "proc_T_S_FunctionHelpUpdate";		
				meta.spDelete = "proc_T_S_FunctionHelpDelete";
				meta.spLoadAll = "proc_T_S_FunctionHelpLoadAll";
				meta.spLoadByPrimaryKey = "proc_T_S_FunctionHelpLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private TSFunctionHelpMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
